<template>
  <div class="search-selector">
    <div class="selector-line">
      <!-- <div class="selector-key">地区</div> -->
      <div class="selector-value">
        <span
          @click="onSelectRegion(null)"
          :class="{'selected': searchModel.provinceId === null}">
          全部
        </span>
        <span
          @click="onSelectRegion(region.provinceId)"
          :class="{'selected': searchModel.provinceId === region.provinceId}"
          :key="'region'+index"
          v-for="(region, index) in regionList">
          {{region.provinceName}}({{region.count}})
        </span>
      </div>
    </div>
    <div class="search">
      <div class="input-box">
        <input v-model="searchModel.keyWord" type="text" placeholder="请输入学校名称查询">
      </div>
      <div
        @click="doSearchName"
        class="search-btn">搜索
      </div>
    </div>
  </div>
</template>

<script>
import { simplifyArray } from '../../../utils/array.util'

export default {
  name: 'SearchSelector',
  data () {
    return {
      searchModel: {
        provinceId: null,
        keyWord: null,
      },
      regionList: [],
    }
  },
  mounted () {
    this.getRegionList()
  },
  methods: {
     getRegionList () {
      this.$http.get('/liveVideoController/getVideoCountByProvince').then(value => {
        this.regionList = value
      })
    },
    doSearchName () {
      this.$emit('doSearch', this.searchModel)
    },
     onSelectRegion (id) {
      this.searchModel.provinceId = id
      this.$emit('doSearch', this.searchModel)
    }
  }
}
</script>

<style scoped lang="less">
  .search-selector {
    box-sizing: border-box;
    padding: 20px 0;
    .selector-line {
      display: flex;
      line-height: 30px;
   
      align-items: baseline;
      padding:10px 0
    }

    .selector-key {
      width: 80px;
      height: 28px;
      background: #9CA2A9;
      border-radius: 22px 0 12px 22px;
      text-align: center;
      font-size: 14px;
      color: #FFFFFF;
      line-height: 28px;
      margin-right: 24px;
    }

    .selector-value {
      flex: 1;
      overflow-y: auto;
      overflow-x: hidden;
      span:hover {
         color: #FF6B51;
      }

      .selected {
        color: #FF6B51;
      }

      span {
        word-break: keep-all;
        margin-right: 48px;
        color: #646A73;
        cursor: pointer;
      }
    }

    .search {
      .input-box {
        display: inline-block;
        width: 615px;
        height: 40px;
        margin-top: 20px;
        padding-left: 35px;
        background-image: url("/images/sh.png");
        background-size: 20px 20px;
        background-repeat: no-repeat;
        background-position: 10px 9px;

        input {
          width: 100%;
          &::-webkit-input-placeholder {
            color: #C3C6CB;
          }
        }
      }

      .search-btn {
        display: inline-block;
        width: 80px;
        height: 40px;
        margin-left: 16px;
        text-align: center;
        line-height: 40px;
        background: #FF6B51;
        border-radius: 4px;
        color: #FFFFFF;
        cursor: pointer;
        &:focus, &:hover {
          background-color: rgba(255, 107, 81, 0.77);
        }
      }
    }
  }
</style>
